package com.youxue.teachin.set.child.my;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import com.Navigator;
import com.library.uiframework.fragment.BaseFragment;
import com.youxue.teachin.R;
import com.youxue.teachin.common.vo.UserVO;
import com.youxue.teachin.user.userSystem.UserSystem;

/**
 * 个人账号
 *
 * @author: zhiwei
 * @date: 2017-10-06 23:33
 * @version: 9.1.0
 */
public class SelfAccountFragment extends BaseFragment implements OnClickListener {
    private View mRootView;
    private TextView mPhone;
    private TextView mChangePhone;
    private TextView mChangePasword;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.set_self_account_fragment, container, false);
        initView(view);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        hideInputMethod();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.change_phone) {
            mChangePasword.setSelected(false);
            mChangePhone.setSelected(true);
            new Navigator.Builder()
                .setPageName("set_chagne_phone")
                .addParameter("phone", phone)
                .build().open();
        } else if (id == R.id.change_pasword) {
            mChangePasword.setSelected(true);
            mChangePhone.setSelected(false);
            new Navigator.Builder()
                .setPageName("set_chagne_password")
                .addParameter("phone", phone)
                .build().open();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        updatePhone();
    }

    String phone = "";

    private void initView(View rootView) {
        mRootView = rootView;
        mPhone = (TextView)rootView.findViewById(R.id.phone);
        mChangePhone = (TextView)rootView.findViewById(R.id.change_phone);
        mChangePasword = (TextView)rootView.findViewById(R.id.change_pasword);

        mChangePasword.setOnClickListener(this);
        mChangePhone.setOnClickListener(this);

        mChangePhone.setSelected(true);
        updatePhone();
    }

    private void updatePhone() {
        UserVO userVO = UserSystem.getInstance().getUserVO();
        if (userVO != null) {
            phone = userVO.phone;
        }
        mPhone.setText("你的手机号："+ phone);
    }
}
